#!/usr/bin/env python

import gtk
import copy
import cairo

GODAMA   = 5
ICHIDAMA = 1

class GodamaIchidama:
    gi_type = None
    value = None
    image_set = None
    image_unset = None
    isset = False
    window = None
    y = None
    x = None
    def __init__(self, gi_type, window, x, y):
        self.window = window
        self.y = y
        self.x = x

        self.gi_type = gi_type
        self.image_set = self.loadImage("data/godama_ichidama_idle.png")
        self.image_unset = self.loadImage("data/godama_ichidama_moved.jpg")
        self.put(x, y)

        self.image_unset.connect('button_press_event', self.countDown )
        self.image_set.connect('button_press_event', self.countUp )

    def countUp(self, widget, args):
        self.put(self.x,self.y+20)

    def countDown(self, widget, args): 
        self.put(self.x,self.y-20)

    def loadImage(self, filename):
        image = gtk.Image()
        image.set_from_file(filename)
        ev = gtk.EventBox()
        ev.show()
        ev.add(image)
        return ev

    def put(self,x,y):
        self.window.window_area.put(self.image_set, x, y)

    def doSet(self, isset):
        self.isset = isset

    def checkSet(self):
        return self.isset

    def getType(self):
        return self.gi_type

    def getValue(self):
        return self.value

    def getImage(self):
        if self.isset:
            return self.image_set
        else:
            return self.image_unset

    def newInstance(self, gi_type):
        return GodamaIchidama(gi_type)

class Keta:
    window = None
    godama = []
    ichidama = []

    def __init__(self, window, x, y):
        self.window = window

        # keta (sticks)
        self.keta = gtk.Image()
        self.keta.set_from_file("data/keta.jpg")
        self.window.window_area.put(self.keta,x,y)


        # godama (5)
        self.godama.append(GodamaIchidama(GODAMA, self.window,
                          x - 23,18))
        # ichidama (1)
        for i in range(0, 4):
            self.ichidama.append(GodamaIchidama(ICHIDAMA, self.window, 
                                  x - 23, 180 - (i*28)))

class Hari:
    window = None

    def __init__(self, window):
        self.window = window

        # hari (inner divisor)
        self.hari = gtk.Image()
        self.hari.set_from_file("data/hari.jpg")
        self.window.window_area.put(self.hari,32,64)

class Waku:
    window = None
    hari = None
    keta = []

    def __init__(self, window):
        self.window = window

        # waku (border)
        self.waku = gtk.Image()
        self.waku.set_from_file("data/waku.jpg")
        self.window.window_area.put(self.waku, 0, 0)

        # init the class
        for i in range(0,9):
            self.keta.append(Keta(self.window,580 - (i*63),18))

        hari = Hari(self.window)

class Window(gtk.Window):
    waku = None

    def __init__(self, parent=None):
        gtk.Window.__init__(self)
        try:
            self.set_screen(parent.get_screen())
        except AttributeError:
            self.connect('destroy', lambda *w: gtk.main_quit())

        # size and name
        self.set_title("pybaco")
        self.set_default_size(664,226)
        #self.set_has_frame(False)
        #self.set_decorated(False)

        # window area
        self.window_area = gtk.Fixed()
        self.add(self.window_area)

        # init the class
        self.waku = Waku(self)

        # let's show all
        self.show_all()

def main():
    pybaco = Window()
    gtk.main()

if __name__ == '__main__':
    main()
